#!/bin/bash

# 编译Swift应用程序
echo "正在编译 Windows Style Taskbar..."

# 设置变量
APP_NAME="WindowsStyleTaskbar"
BUILD_DIR="build"
SOURCES="main.swift GeometryUtils.swift WindowManager.swift TaskbarView.swift TaskbarController.swift"

# 创建构建目录
mkdir -p "$BUILD_DIR"

# 编译应用程序
swiftc -o "$BUILD_DIR/$APP_NAME" \
    -target x86_64-apple-macosx10.15 \
    -framework Cocoa \
    -framework SwiftUI \
    -framework ApplicationServices \
    -framework CoreGraphics \
    $SOURCES

if [ $? -eq 0 ]; then
    echo "编译成功！"
    echo "可执行文件位置: $BUILD_DIR/$APP_NAME"
    
    # 创建应用程序包结构
    APP_BUNDLE="$BUILD_DIR/$APP_NAME.app"
    mkdir -p "$APP_BUNDLE/Contents/MacOS"
    mkdir -p "$APP_BUNDLE/Contents/Resources"
    
    # 复制可执行文件到正确位置
    cp "$BUILD_DIR/$APP_NAME" "$APP_BUNDLE/Contents/MacOS/"
    
    # 复制Info.plist
    cp "Info.plist" "$APP_BUNDLE/Contents/"
    
    # 确保可执行文件有执行权限
    chmod +x "$APP_BUNDLE/Contents/MacOS/$APP_NAME"
    
    echo "应用程序包创建完成: $APP_BUNDLE"
    echo ""
    echo "运行应用程序:"
    echo "  直接运行: ./$BUILD_DIR/$APP_NAME"
    echo "  或者打开应用包: open $APP_BUNDLE"
    echo ""
    echo "注意: 首次运行时需要在系统偏好设置 > 安全性与隐私 > 辅助功能中授权"
else
    echo "编译失败！"
    exit 1
fi